package com.wootion.dizhi.controller;

import com.wootion.dizhi.entity.Category;
import com.wootion.dizhi.entity.Photograph;
import com.wootion.dizhi.exception.BusinessException;
import com.wootion.dizhi.response.Result;
import com.wootion.dizhi.service.MyPluginService;
import com.wootion.dizhi.vo.Condition;
import com.wootion.dizhi.vo.MoveVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.FileNotFoundException;
import java.util.List;

/**
 * 我的插件(添加插件，数据对比,野外数据归类照片收集)
 */
@RestController
@RequestMapping("/myPlugin")
@Api(tags = "我的插件")
public class MyPluginController {

    @Resource
    private MyPluginService myPluginService;
    /*--------------------------------------野外数据归类照片收集---------------------------------------------*/
    @ApiOperation("野外数据归类照片收集-新建类别")
    @PostMapping("/insertCategory")
    public Result insertCategory(@RequestBody @Validated Category category) throws BusinessException {
        return myPluginService.insertCategory(category);
    }
    @ApiOperation("野外数据归类照片收集-修改类别")
    @PostMapping("/updateCategory")
    public Result updateCategory(@RequestBody @Validated Category category) throws BusinessException {
        return myPluginService.updateCategory(category);
    }

    @ApiOperation("野外数据归类照片收集-删除类别")
    @DeleteMapping("/deleteCategory")
    public Result deleteCategory(@RequestParam(value = "id")String id) throws BusinessException {
        return myPluginService.deleteCategory(id);
    }

    @ApiOperation("野外数据归类照片收集-左侧树结构")
    @GetMapping("/tree")
    public Result tree(){
        return myPluginService.tree();
    }

    @ApiOperation("野外数据归类照片收集-添加文件")
    @PostMapping("/addFile")
    public Result addFile(@RequestParam("id")String id,
                          @RequestParam("files")MultipartFile[] multipartFiles){
        return myPluginService.addFile(id,multipartFiles);
    }

    @ApiOperation("野外数据归类照片收集-文件分页列表")
    @PostMapping("/list")
    public Result list(@RequestBody @Validated Condition condition){
        return myPluginService.list(condition);
    }

    @ApiOperation("野外数据归类照片收集-修改文件名")
    @PutMapping("/updateFileName")
    public Result updateFileName(@RequestBody Photograph photograph){
        return myPluginService.updateFileName(photograph);
    }

    @ApiOperation("野外数据归类照片收集-删除文件(批量删除文件)")
    @DeleteMapping("/deleteFile")
    public Result deleteFile(@RequestBody List<String> ids){
        return myPluginService.deleteFile(ids);
    }

    @ApiOperation("野外数据归类照片收集-移动文件")
    @PutMapping("/moveFile")
    public Result moveFile(@RequestBody MoveVo moveVo){
        return myPluginService.moveFile(moveVo);
    }

    @ApiOperation("野外数据归类照片收集-导出文件")
    @GetMapping("/exportFile")
    public Result exportFile(@RequestParam("id")String id) throws FileNotFoundException {
        return myPluginService.exportFile(id);
    }
    /*-----------------------------------------数据对比---------------------------------------------*/
    @GetMapping("/comparisonData")
    @ApiOperation("数据对比")
    public Result comparisonData(@RequestParam("address")String address,
                                 @RequestParam("experiment")String experiment){
        return myPluginService.comparisonData(address,experiment);
    }

    @GetMapping("/selectDevice")
    @ApiOperation("选择设备和次序号")
    public Result selectDevice(@RequestParam(value = "address",required = false)String address){
        return myPluginService.selectDevice(address);
    }
}
